
import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

data = [3, 4, 5, 5, 2, 4, 7, 8, 11, 8, 12,
    11, 13, 13, 16, 17, 18, 17, 19, 21]
m = len(data)
y = np.array(data).reshape(m,1)
x = np.array(range(0,m)).reshape(m,1)
plt.scatter(x,y,s=30, c="blue", marker="s")

model = tf.keras.Sequential()# ax + b   一层一层的模型
model.add(tf.keras.layers.Dense(1,input_shape=(1,)))  #添加层 dense  输出维度为1  输入的维度为1
model.summary()
model.compile(optimizer="adam",\
				loss="mse")#优化方法，均方差
history = model.fit(x, y, epochs = 5000)

y_out = model.predict(x)
plt.scatter(x,y_out,s=30, c="red", marker="s")
plt.show()
pass

